<template>
	<view class="content">
		<!-- 相册描述 -->
		<view class="uni-flex uni-row in" v-for="(item,index) in addList" :key="index">
			<view class="text">
				<view class="uni-input-wrapper">
				    <input v-model="item.photoName" class="uni-input" placeholder="照片描述"/>
				</view>
			</view>
			<view>
				<image :src="item.photPath" mode="aspectFill"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				describe:null,		//描述
				addList:null,		//选择完成后的图片
				albumArr:null,		
				photoArr:[],		//图片路径
				desArr:[],		//描述
				albumIndex:null //选中相册的下标
			}
		},
		onLoad(option) {
			console.log('option',option)
			this.addList = null
			this.albumArr = null
			this.addList = JSON.parse(option.addList)
			this.albumArr = JSON.parse(option.albumArrpho)
			console.log('addList',this.addList)
			console.log('albumArrpho',this.albumArr)
			/* this.albumIndex = uni.getStorageSync('albumIndex') */
		},
		onBackPress() {
			this.albumArr2 = null
		},
		onNavigationBarButtonTap(item){
			if(item.index == 0){
				this.desArr = []
				this.photoArr = []
				/* 图片和描述 */
				for (var i = 0; i < this.addList.length; i++) {
					this.desArr.push(this.addList[i].photoName)
					this.photoArr.push(this.addList[i].photPath)
				}
				console.log('addList',this.addList)
				console.log('desArr',this.desArr)
				console.log('photoArr',this.photoArr)
				/* 图片路径 */
				var imgarr = []
				var conte = []
				for (var i = 0; i < this.photoArr.length; i++) {
					let jsonobj = {
						name:'file['+i+']',
						uri:this.photoArr[i]
					}
					imgarr.push(jsonobj)
				}
				for (var i = 0; i < this.desArr.length; i++) {
					let jsonobj = {
						name:'content['+i+']',
						uri:this.desArr[i]
					}
					conte.push(jsonobj)
				}
				console.log('conte',conte) 
				console.log('添加的相片路径',imgarr)
				console.log('album_id',this.albumArr.album_id)
				let resData = {
					album_id:this.albumArr.album_id,
					'file[]':imgarr
				}
				
				for(var i = 0; i < this.desArr.length; i++) {
					resData["content["+i+"]"] = this.desArr[i]
				}
				console.log('resData',resData)
				uni.showLoading({
				    title: '请稍后',
					mask:true
				});
				this.$api.apifile('user/video.Photo/imgupload',resData).then(res => {
					console.log('接口状态码',res.statusCode);
					if(res.statusCode == 200){
						console.log('res',res)
						uni.hideLoading();
						uni.showToast({
						    title: '添加成功',
						    duration: 2000
						});
						setTimeout(function() {
							uni.navigateBack({
								delta:1
							})
						},2000)
					}
				})
			}
		},
		methods: {
			/* 添加相册内容 */
			albumListAdd(){
				
			},
		}
	}
</script>

<style>
	.content {
		position: absolute;
		width: 100%;
		height: 100%;
		background-color: #FFFFFF;
	}
	
	.in{
		margin: 40rpx 30rpx 0rpx 30rpx;
		align-items: center;
	}
	
	.text{
		background-color: #FAFAFA;
		width: 500rpx;
		height: 160rpx;
		margin: 0rpx 30rpx 0rpx 0rpx;
		border-radius: 5px;
	}
	
	.text input{
		background-color: #FAFAFA;
		font-size: 28rpx;
	}
	
	.in image{
		width: 160rpx;
		height: 160rpx;
		border-radius: 10rpx;
	}
</style>
